#include <iostream>
using namespace std;

class Engine 
{
public:
	virtual ~Engine() {}
	virtual void run()=0;
};

class BMW_Engine: public Engine 
{
public:
	void run() 
	{
		cout << "run the BMW's engine" << endl;
	}
};

class Audi_Engine: public Engine 
{
public:
	void run() 
	{
		cout << "run the Audi's engine." <<endl;
	}
};

class Tire 
{
public:
	virtual ~Tire() {}
	virtual void load()=0;
};

class BMW_Tire: public Tire 
{
public:
	void load() 
	{
		cout << "load the tire of BMW" << endl;
	}
};

class Audi_Tire: public Tire 
{
public:
	void load() 
	{
		cout << "load the tire of Audi" << endl;
	}
};

class Abstract_Factory 
{
public:
	virtual ~Abstract_Factory() {}
	virtual Engine* get_engine()=0;
	virtual Tire* get_tire()=0;
};

class BMW_Factory: public Abstract_Factory 
{
public:
	Engine* get_engine() 
	{
		return new BMW_Engine();
	}
	Tire* get_tire() 
	{
		return new BMW_Tire();
	}
};

class Audi_Factory: public Abstract_Factory 
{
public:
	Engine* get_engine() 
	{
		return new Audi_Engine();
	}
	Tire* get_tire() 
	{
		return new Audi_Tire();
	}
};

int main() 
{
	cout << "/***create the BMW factory***/" << endl;
	Abstract_Factory* factory = new BMW_Factory();
	Engine* engine = factory->get_engine();
	engine->run();
	Tire* tire = factory->get_tire();
	tire->load();

	cout << "/***create the Audi factory***/" << endl;
	factory = new Audi_Factory();
	engine = factory->get_engine();
	engine->run();
	tire = factory->get_tire();
	tire->load();
	return 0;
}
